package com.chy.mybatis.plugin;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;

import java.util.Properties;

/**
 * 功能：
 * <p>
 * ──────────────────────────────────────────
 * version  变更日期       修改人    修改说明
 * ------------------------------------------
 * V1.0.0   2022/3/10     CHY     初版
 * ──────────────────────────────────────────
 */
@Intercepts({
        @Signature(type = Executor.class,method = "update",args = {MappedStatement.class,Object.class})
})
public class MyPlugin implements Interceptor {

    Properties props = null;


    @Override
    public Object intercept(Invocation invocation) throws Throwable {

        System.out.println("before..........");
        Object proceed = invocation.proceed();
        System.out.println("after..........");
        return proceed;
    }

    @Override
    public Object plugin(Object target) {
        System.out.println("调用生成代理对象..............." + target.getClass().getName());
        return Plugin.wrap(target,this);
    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println(properties.get("dbType"));
        this.props = properties;
    }
}
